package mvc.controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import mvc.model.IModelCurve;
import mvc.view.ViewCurve;

import org.geom.Point2D;


public abstract class MouseController extends Controller implements MouseListener, MouseMotionListener, KeyListener{

	public static boolean mousePressed = false;
	
	protected enum Action { ROTATE, TRANSLATE, SCALE };
	protected Action action = Action.TRANSLATE;
	
	protected Point2D mouseDown;// = new Point2D();
	protected int deltax;
	protected int deltay;
		
	public MouseController(IModelCurve model, ViewCurve view, String param) {
		super(model, view, param);
		
		view.addMouseController(this);
	}

	@Override
	public void mousePressed(MouseEvent e) {
		this.mouseDown = new Point2D(e.getX(), e.getY());

		view.setFocusable(true);
		view.requestFocus();
		
		view.updateFromController();
		
		mousePressed = true;
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		mousePressed = false;
		mouseMoved(e);
	}
	
	@Override
	public void mouseDragged(MouseEvent e) {
		deltax = e.getX() - (int)mouseDown.x;
		deltay = e.getY() - (int)mouseDown.y;

		mouseDown.x = e.getX();
		mouseDown.y = e.getY();
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		view.updateFromModel();
	}

	@Override
	public void keyPressed(KeyEvent e) {
		char c = e.getKeyChar();
		if ( c=='t' || c=='T') action = Action.TRANSLATE;
		if ( c=='r' || c=='R') action = Action.ROTATE;
		if ( c=='s' || c=='S') action = Action.SCALE;
		System.out.println("MouseController > keyPRessed > action:"+action);
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	
	//---------------------------------------------------------------------- unimplemented
	
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
}
